package cn.slipi.pan.web.mapper;

import cn.slipi.pan.web.entity.AuthEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * mapper
 */
@Mapper
public interface AuthMapper extends BaseMapper<AuthEntity> {

    default List<AuthEntity> listAll() {
        return this.selectList(new LambdaQueryWrapper<>());
    }

    default AuthEntity queryById(Integer id) {
        return this.selectOne(new LambdaQueryWrapper<AuthEntity>().eq(AuthEntity::getId, id));
    }

    default AuthEntity queryByLicense(String licenseId) {
        AuthEntity authEntity = this.selectOne(new LambdaQueryWrapper<AuthEntity>().eq(AuthEntity::getLicense, licenseId).eq(AuthEntity::getStatus, "ON"));
        if (authEntity != null) {
            authEntity.setConnectTime(new Date());
            this.updateById(authEntity);
        }
        return authEntity;
    }

    default List<AuthEntity> findByIds(Set<Integer> ids) {
        return selectBatchIds(ids);
    }
}
